package sunshine.commcon.util.util;

import com.alibaba.druid.filter.config.ConfigTools;

public class DruidPasswordGenerator {
    public static void main(String[] args) {
        try {
            // Generate new key pair
            String[] keyPair = ConfigTools.genKeyPair(512);
            String privateKey = keyPair[0];
            String publicKey = keyPair[1];
            
            System.out.println("Private key: " + privateKey);
            System.out.println("Public key: " + publicKey);
            
            // Encrypt password using the new private key
            String password = "sunshine8023";
            String encryptedPassword = ConfigTools.encrypt(privateKey, password);
            System.out.println("Encrypted password: " + encryptedPassword);
            
            // Verify decryption
            String decryptedPassword = ConfigTools.decrypt(publicKey, encryptedPassword);
            System.out.println("Decryption verification: " + decryptedPassword);
            
            // Generate configuration information
            System.out.println("\nPlease use the following configuration in application.yml:");
            System.out.println("password: " + encryptedPassword);
            System.out.println("connection-properties: config.decrypt=true;config.decrypt.key=" + publicKey);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}